package com.muyu.system.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DmShoppingSku;
import com.muyu.system.service.IDmShoppingSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品skuController
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/sku")
public class DmShoppingSkuController extends BaseController {
    @Autowired
    private IDmShoppingSkuService dmShoppingSkuService;

    /**
     * 查询商品sku列表
     */
    //@RequiresPermissions("system:sku:list")
    @GetMapping("/list")
    public Result list(DmShoppingSku dmShoppingSku) {
        startPage();
        List<DmShoppingSku> list = dmShoppingSkuService.selectDmShoppingSkuList(dmShoppingSku);
        return getDataTable(list);
    }

    /**
     * 导出商品sku列表
     */
    //@RequiresPermissions("system:sku:export")
    @Log(title = "商品sku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmShoppingSku dmShoppingSku) {
        List<DmShoppingSku> list = dmShoppingSkuService.selectDmShoppingSkuList(dmShoppingSku);
        ExcelUtil<DmShoppingSku> util = new ExcelUtil<DmShoppingSku>(DmShoppingSku.class);
        util.exportExcel(response, list, "商品sku数据");
    }

    /**
     * 获取商品sku详细信息
     */
    //@RequiresPermissions("system:sku:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(dmShoppingSkuService.selectDmShoppingSkuById(id));
    }

    /**
     * 新增商品sku
     */
    //@RequiresPermissions("system:sku:add")
    @Log(title = "商品sku", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DmShoppingSku dmShoppingSku) {
        return toAjax(dmShoppingSkuService.insertDmShoppingSku(dmShoppingSku));
    }

    /**
     * 修改商品sku
     */
    //@RequiresPermissions("system:sku:edit")
    @Log(title = "商品sku", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DmShoppingSku dmShoppingSku) {
        return toAjax(dmShoppingSkuService.updateDmShoppingSku(dmShoppingSku));
    }

    /**
     * 删除商品sku
     */
    //@RequiresPermissions("system:sku:remove")
    @Log(title = "商品sku", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(dmShoppingSkuService.deleteDmShoppingSkuByIds(ids));
    }
}
